#!/bin/bash

echo "----Running Code Coverage----"

# Remove multiprocessing coverage files in case a previous combine wasn't performed
rm .coverage.*
rm -fR cover/
# Remove the main coverage file (.coverage)
coverage erase

# Discover and run all tests
coverage run --concurrency=multiprocessing ./scripts/run_tests.py discover -v

coverage combine
res_combine=$?
if [ $res_combine -ne 0 ]
then
  echo -e "Travis Build FAILURE: Coverage combine failed"
  exit 1
fi

coverage report --fail-under=100
coverage_report=$?
if [ $coverage_report -ne 0 ]
then
  echo -e "Travis Build FAILURE: Coverage percentage failed"
  exit 1
fi